const app = getApp();
var api = require('../../utils/api.js');
var util = require('../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		total: '',
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		this.setData({
			code: options.code
		})
		this.getInfo()
	},

	//餐券信息
	getInfo: function () {
		var that = this;
		api.POST({
			url: app.globalData.base_url + 'Mealticket/getCodeInfo',
			params: {
				linkCode: that.data.code
			},
			success: function (res) {
				if (res.data.code == '') {
					that.setData({
						list: res.data.data.list,
						total: res.data.data.total
					})
				} else {
					util.showError(res.data.message);
					return;
				}
			}
		});
	},

	back:function(){
		wx.switchTab({
			url: '/pages/business/business'
		})
	},

	//继续核销
	continueVerification:function(){
		var that = this;
		wx.scanCode({
			onlyFromCamera: true,
			success: (res) => {
				var rest = res.result;
				if (rest.indexOf("code") < 0 || rest.indexOf("ticketVerification") < 0) {
					util.showStatus("请扫描餐券二维码");
					return;
				}
				var arr = res.result.split("?");
				var str1 = arr[1];
				var code = str1.split("=")[1];
				wx.redirectTo({
					url: '/pages/mealTicketVerification/mealTicketVerification?code=' + code,
				})
			}
		});
	}
})